// 获取第n行第m个值
function get(n, m) {
    if (m > n) {
        throw new Error('错误的参数')
    }
    if (m === 1 || m === n) {
        return 1
    } else {
        return get(n - 1, m - 1) + get(n - 1, m)
    }
}
// 生成杨辉三角
function yangHuiTriangle (n) {
    var arr = []
    for(var i =1; i<=n; i++) {
        arr[i-1] = []
        for (var j = 1; j <= i; j++) {
            let result = 0
            if (j ==1 || j ===i) {
                result = 1
            } else {
                result = arr[i-2][j-2] + arr[i-2][j-1]
            }
            arr[i-1].push(result)
        }
    }
    return arr
}
// 打印杨辉三角
function printTriangle (n) {
    let result = yangHuiTriangle(n)
    let len = result.length
    let str = ''
    result.forEach((item, index) => {
        let padding = new Array(len - index).join(' ')
        str += padding + item.join(' ') + '\n'
    })
    return str  
}

console.log(printTriangle(20))